import {combineReducers} from "redux"
import {ADD_ACTION,SPLICE_ACTION,SHIFT_ACTION,UNSHIFT_ACTION} from "../action/index"
const initialState=[{a:"aaa"},{ b:"bbb"},{c:"ccc"},{ d:"ddd"},{ e:"eee"}]
function changeState(state = initialState, action={type:"",index:"",value:""}){
   
    switch (action.type) {
        case ADD_ACTION:
            state.push(action.value);
            return [...state];
        case SPLICE_ACTION:
            if(action.value){
                state.splice(action.index,1,action.value);
            }else{
                state.splice(action.index,1);
            }
            return [...state]
        case UNSHIFT_ACTION:
            state.unshift(action.value);
            return [...state]
        default:
            return [...state]
    }

}

export default combineReducers({changeState})